#ifndef WEBSERVER_H
#define WEBSERVER_H

#include <QTcpServer>

class ThreadOfWebClientSocket;
class DBOInWebserver;
class QTimer;
class QSqlQuery;

class WebServer : public QTcpServer
{
    Q_OBJECT
public:
    explicit WebServer(quint16 port,QString strDefaultPage,
            quint16 updateInterval,quint32 updateIntervalPic,QObject *parent = 0);

signals:
    void sigMsgBox(QString title,QString text);
    //URI请求的回复。与webClient的槽连接
    void sigReplyURI(QByteArray reply);
    void sigErrorInfo(QString errorStr);

    //通知对应的槽函数，注册该传感器。一般是因为漏注册了这个活动的传感器。
    void sigRegSensor(qint64 nodeMacAddr,qint16 sensorID,qint8 sensorOnWork);
public slots:
    void slotListen();
    void slotTimerEventForUpdateWebSensor();
    void slotTimerEventForUpdateWebPic();

    void slotAddNode(qint64  nodeMacAddr,QByteArray nodeName);
    void slotDeleteNode(qint64  nodeMacAddr,QByteArray nodeName);
    void slotAddSensor(qint64 nodeMacAddr,qint16 sensorID);
    void slotConnectDB();

public:
    void initWebPages();//初始化
    bool initCompleted;

private:
    void incomingConnection(int handle);
    void deleteFilesInDir(QString strDir); //删除目录下的所有文件
    void copyDir(QString newDirName,QString oldDirName);
    QTimer* timerForUpdateWebSensor;
    QTimer* timerForUpdateWebPic;

    quint16 webPort;
    quint16 updtInterval;
    quint32 updtIntervalPic;//图片更新间隔
    QString defaultPage;
    ThreadOfWebClientSocket *lastThreadSocket;
    DBOInWebserver *dboInWS;


};

#endif // WEBSERVER_H
